
<script>

$(function()
{
	$("#tbl_tree").treetable({expandable : true, expanderTemplate : "<a>&nbsp;</a>"});
	
});

function dialog_tree_select(id, parentId, name)
{
	$("#hdn_tree_id").val(id);
	$("#hdn_tree_parent_id").val(parentId);
	$("#txt_tree_name").val(name);
	
	if (tree_onselect)
	{
		tree_onselect(id, parentId, name);
	}
	
}

function dialog_tree_unselect()
{
	$("#hdn_tree_id").val("");
	$("#hdn_tree_parent_id").val("");
	$("#txt_tree_name").val("");
	
	if (tree_onunselect)
	{
		tree_onunselect();
	}
}

</script>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="div_model">
	<div class="am-modal-dialog">
		<div class="am-modal-hd">
			选择栏目
			<a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
		</div>
		<div class="am-modal-bd" id="div_dialog_grid">
			<table class="am-table am-table-striped am-table-hover am-table-compact" id="tbl_tree">
				<thead>
				<tr>
					<th>名称</th>
					<th width="100">操作</th>
				</tr>
				</thead>
				<tbody>
				<#if treeList?? && treeList?size &gt; 0>
				<@tree map=treeList key="0" />
				</#if>
				</tbody>
			</table>
			<a href="javascript:void(0)" onclick="dialog_tree_unselect()" class="am-btn am-btn-danger am-radius am-margin-top" data-am-modal-close>取消选择</a>
		</div>
	</div>
</div>

<#macro tree map key count=0>
	<#assign voList=map[key]! />
	
	<#if voList??>
	<#list voList as vo>
			<tr id="tree_tr_${vo.id}" data-tt-id="${vo.id}" data-tt-parent-id="${vo.parentId!}">
				<td title="${vo.name!}">${vo.name!}</td>
				<td>
					<div class="am-btn-group">
						<a href="javascript:void(0)" onclick="dialog_tree_select('${vo.id}', '${vo.parentId!"0"}', '${vo.name}')"
							class="am-btn am-btn-primary am-btn-sm am-radius" data-am-modal-close>选择</a>
					</div>
				</td>
			</tr>
			<@tree map=map key=vo.id?string count=count+1 />
	</#list>
	</#if>
	
</#macro>
